package com.spsy.product.controller;

import com.spsy.common.core.utils.poi.ExcelUtil;
import com.spsy.common.core.web.controller.BaseController;
import com.spsy.common.core.web.domain.AjaxResult;
import com.spsy.common.core.web.page.TableDataInfo;
import com.spsy.common.log.annotation.Log;
import com.spsy.common.log.enums.BusinessType;
import com.spsy.common.security.annotation.RequiresPermissions;
import com.spsy.product.domain.ProductDetail;
import com.spsy.product.service.IProductDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 商品详情Controller
 * 
 * @author ruoyi
 * @date 2025-09-28
 */
@RestController
@RequestMapping("/product_detail")
public class ProductDetailController extends BaseController
{
    @Autowired
    private IProductDetailService productDetailService;

    /**
     * 查询商品详情列表
     */
    @RequiresPermissions("product_detail:product_detail:list")
    @GetMapping("/list")
    public TableDataInfo list(ProductDetail productDetail)
    {
        startPage();
        List<ProductDetail> list = productDetailService.selectProductDetailList(productDetail);
        return getDataTable(list);
    }

    /**
     * 导出商品详情列表
     */
    @RequiresPermissions("product_detail:product_detail:export")
    @Log(title = "商品详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProductDetail productDetail)
    {
        List<ProductDetail> list = productDetailService.selectProductDetailList(productDetail);
        ExcelUtil<ProductDetail> util = new ExcelUtil<ProductDetail>(ProductDetail.class);
        util.exportExcel(response, list, "商品详情数据");
    }

    /**
     * 获取商品详情详细信息
     */
    @RequiresPermissions("product_detail:product_detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productDetailService.selectProductDetailById(id));
    }

    /**
     * 新增商品详情
     */
    @RequiresPermissions("product_detail:product_detail:add")
    @Log(title = "商品详情", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductDetail productDetail)
    {
        return toAjax(productDetailService.insertProductDetail(productDetail));
    }

    /**
     * 修改商品详情
     */
    @RequiresPermissions("product_detail:product_detail:edit")
    @Log(title = "商品详情", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductDetail productDetail)
    {
        return toAjax(productDetailService.updateProductDetail(productDetail));
    }

    /**
     * 删除商品详情
     */
    @RequiresPermissions("product_detail:product_detail:remove")
    @Log(title = "商品详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productDetailService.deleteProductDetailByIds(ids));
    }
}
